package ai

import (
	"fmt"

	http_label_center "gobase/http_work_flow/label_center"
	diffx "gobase/http_work_flow/label_center/ai/diff"
)

// 数据转绘制
// percentage = 100 完全相同
func Data2DiffImage(value *diffx.RespDiffImage, percentage float64) (_frame http_label_center.Tag, _err error) {
	var metas = make([]http_label_center.Meta, 0)
	if value.Code != 200 {
		_err = fmt.Errorf("图片对比失败 %+v", value)
		return
	}
	if percentage <= 0 { //默认20
		percentage = 20 //相似度 大于此值 忽略报警
	}
	//  5 10
	if value.Percentage > percentage {
		_err = fmt.Errorf("图片对比 忽略 %+v", value)
		return
	}
	var meta = http_label_center.Meta{
		X:           1920 / 4,
		Y:           1080 / 4,
		Remark:      fmt.Sprintf("图片相似度:%f", value.Percentage),
		TypeId:      1,
		ProtoWidth:  1920,
		ProtoHeight: 1080,
		Rect: &http_label_center.Rect{
			Width:  1920 / 2,
			Height: 1080 / 2,
			Text:   "存在异常",
			Center: false,
		},
	}
	metas = append(metas, meta)
	_frame = http_label_center.Tag{
		Metas: metas,
		AbsoluteTime: &http_label_center.AbsoluteTime{
			CenterUnixMs: value.CenterUnixMs, //TODO: 时间戳
			DurationMs:   2000,
		},
	}
	return
}
